﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web;

namespace He.Common
{
    public class InputHelper
    {
        /// <summary>
        /// 获取请求的流
        /// </summary>
        /// <returns></returns>
        public static string GetInpugStream()
        {
            Stream inputStream = HttpContext.Current.Request.InputStream;
            byte[] buffer = new byte[inputStream.Length];
            inputStream.Read(buffer, 0, (int)inputStream.Length);
            return Encoding.UTF8.GetString(buffer);
        }

        /// <summary>
        /// 字符串转化为流
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static Stream ConvertToStream(string str)
        {
            byte[] buffer = System.Text.Encoding.Default.GetBytes(str);
            Stream stream = new MemoryStream(buffer);
            return stream;
        }
    }
}
